<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\TransferRecordRequest;
use App\CustHub\Service\ChTransferRecordService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: 'ch/transferRecord'),ApiAuth,VerifySignature]
class TransferRecordController extends BaseController
{
    #[Inject]
    protected ChTransferRecordService $service;

    /**
     * @param TransferRecordRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(TransferRecordRequest $request): ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success('工单提交成功') : $this->error('工单提交失败,请重试');
    }

    /**
     * 获取对公转账配置
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('getConfig')]
    public function getCorporateTransferConfig(): ResponseInterface
    {
        return $this->success($this->service->getCorporateTransferConfig());
    }
}